<template>

  <div class="logincontainer">
    <span class="span-title">{{$getTextByLangKey('系统登录')}}</span>
    <el-input v-model="username" :placeholder="$getTextByLangKey('请输入用户名')"></el-input>
    <el-input v-model="password" type="password" :placeholder="$getTextByLangKey('请输入密码')"></el-input>
    <!--<el-checkbox v-model="remember">记住我</el-checkbox>-->
    <br>
    <el-button type="primary" @click="toLogin">{{ $getTextByLangKey('登录') }}</el-button>
  </div>
</template>
<script>


  import request from '@/common/js/request'
  import util from '@/common/js/util'

  // import {}

  export default {
    name: "login-component",
    data() {
      return {
        username: "",
        password: "",
        remember: true,
      }
    },
    components: {},
    created() {
      console.log('redirect',this.$route)
    },
    methods: {
      toLogin: function () {
        if (this.username.trim() === ''||this.password.trim() === '') {
          util.showErrorToast(this.$getTextByLangKey('用户名和密码不能为空'));
          return
        }
        let username = this.username.trim()
        let password = this.password.trim()


        this.$wlsRequset.requestLogin(username,password,res=>{
          localStorage.setItem('username',username)
          localStorage.setItem('password',password)
          util.showSuccessToast(this.$getTextByLangKey('登录成功'))

          const redirect_url = this.$route.query.redirect?decodeURIComponent(this.$route.query.redirect) : ''
          setTimeout(function () {
            if(redirect_url){
              util.linkToPath(redirect_url)
            }else{
              util.linkToPath('/wrapper/welcome')
            }
          }, 800)

        },err=>{
          util.showErrorToast(err.data.message);
          console.log('err',err)
        })


//        if(username==='admin'&&password === '12345678'){
//          util.showSuccessToast('登陆成功')
//
//          setTimeout(function () {
//            util.linkToPath('/wrapper/welcome')
//          }, 800)
//
//          localStorage.setItem('username',username)
//          localStorage.setItem('password',password)
//        }else{
//          util.showErrorToast('密码或者账号错误' )
//        }
//        request.requestLogin(username,password,res=>{
//          util.showSuccessToast('登陆成功'+res.data.data.tokenId)
//
//          setTimeout(function () {
//            util.linkToPath('/wrapper/welcome')
//          }, 800)
//
//        })
      }
    }
  }

</script>

<style scoped lang="stylus" rel="stylesheet/stylus">


  .logincontainer {
    background: @bg;
    width: 450px;
    height: 300px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -150px;
    margin-left: -225px;
    border: 1px solid rgb(200, 200, 200);
    border-radius: 10px;
    box-shadow: 0px 0px 20px rgb(200, 200, 200);
  }


  .span-title {
    display: inline-block;
    text-align: center;
    width: 100%;
    font-size: 20px;
    font-weight: bold;
    padding: 20px 0px;
  }

  .el-input, .el-button {
    width: 420px;
    margin: 10px 15px;
  }

  .el-checkbox {
    margin: 10px 25px;
  }

  .el-button {

  }
</style>
